#include <iostream>

using namespace std;

int t;
string s;
int main()
{
    cin >> t;
    while(t--)
    {
        cin >> s;
        int sum = 0;
        bool flag = false;
        for(auto e : s)
        {
            sum += e - '0';
            if(e == '0') flag = true;
        }
        if(flag) cout << sum + 9 << endl;
        else cout << sum + 8 << endl;
    }
    return 0;
}